package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.impl.ShopcartServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.xmlbeans.impl.xb.xsdschema.Public;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/shoppingCart")
@Api(tags = "C端-购物车接口")
@Slf4j
public class ShopcartController {
    @Autowired
    private ShopcartServiceImpl shopcartServiceImpl;
    @ApiOperation("C端-添加购物车")
    @PostMapping("/add")
    public Result add(@RequestBody ShoppingCartDTO shoppingCartDTO) {
        log.info("菜品id或者套餐id：{}", shoppingCartDTO.getDishId());
        shopcartServiceImpl.add(shoppingCartDTO);
        return Result.success();
    }
    //查看购物车里面的信息
    @ApiOperation("C端-查看购物车")
    @GetMapping("/list")
    public Result<List<ShoppingCart>> list() {
        log.info("查看购物车");
        List<ShoppingCart> list = shopcartServiceImpl.list();
        return Result.success(list);
    }
    //清空购物车
    @ApiOperation("C端-清空购物车")
    @DeleteMapping("/clean")
    public Result clean() {
        shopcartServiceImpl.clean();
        return Result.success();
    }
    @ApiOperation("C端-删除购物车中的商品")
    @PostMapping("/sub")
    public Result sub(@RequestBody ShoppingCartDTO shoppingCartDTO) {
        shopcartServiceImpl.sub(shoppingCartDTO);
        return Result.success();
    }
}